#include <stdio.h>
#include <stdlib.h>

#include "sqlite3.h"

#define INSERT "insert into studen values(NULL, '%s','%s');"
#define DBNAME "mysql.db"

int main(void)
{
	sqlite3 *ppdb;
	int ret = sqlite3_open(DBNAME, &ppdb);  //打开数据库
	if(ret != SQLITE_OK)
	{
		perror("open fail");
		return -1;
	}
	
	char insert[128]={0};
	char name[32] = {0};
	char ip[32] = {0};

	printf("Content-Type:text/html;charset=UTF-8\n\n");
	char *data = getenv("QUERY_STRING");
	if(data == NULL)
		printf("<p>error no input </p>\n\n");
	else
		sscanf(data,"name=%s&ip=%s",name,ip);
		
	
	

	sprintf(insert,INSERT,name,ip);

	char *err = NULL;
	ret = sqlite3_exec(ppdb, insert, NULL, NULL, &err); //err 数据库错误输出
	if(ret != SQLITE_OK)
	{
		printf("%s\n\n",err);
		return -1;
	}	
	printf("install suc");
	
	return 0;	
}